package com.itjiange;

/**
 * 享元/蝇量模式
 *
 * @author ItJianGe
 * @data 2024/8/12 16:03
 */
public class FlyweightMain {

    private static MarketInfoClient marketInfoClient = new MarketInfoClient();

    public static void main(String[] args) {
        PersonInfo personInfo1 = new PersonInfo("迪丽热巴", 30, "城关区", 2);
        PersonInfo personInfo2 = new PersonInfo("杨幂", 32, "七里河区", 1);
        PersonInfo personInfo3 = new PersonInfo("宋雨琦", 23, "西固区", 3);

        printInfo(personInfo1);
        printInfo(personInfo2);
        printInfo(personInfo3);
    }

    public static void printInfo(PersonInfo personInfo) {
        String name = personInfo.getName();
        int age = personInfo.getAge();
        String address = personInfo.getAddress();
        int marketId = personInfo.getMarketId();

        MarketInfo marketInfo = marketInfoClient.getMarketInfo(marketId);

        System.out.printf("姓名：%s，年龄：%d，地址：%s，就近超市：%s\n", name, age, address, marketInfo.getMarketAddress());
    }
}